<script setup>
import { ref, onMounted } from 'vue'
import { getMemberInfo } from '@/api/member.js'

const userId = localStorage.getItem("userId")
const memberInfo = ref(null)

const showPrivilege = ref(false) // 会员特权弹窗
const showLevelRule = ref(false) // 等级规则弹窗

onMounted(async () => {
  try {
    const res = await getMemberInfo(userId)
    console.log("🔍 后端返回数据：", res.data)

    if (res.data.code === 200) {
      memberInfo.value = res.data.data
    } else {
      alert(res.data.message || "未找到会员")
    }
  } catch (err) {
    console.error("请求失败：", err)
  }
})
</script>

<template>
  <div class="member-container" v-if="memberInfo">

    <h2 class="title">会员中心</h2>

    <div class="card">
      <div class="row">
        <span class="label">会员账号：</span>
        <span class="value">{{ memberInfo.memberAccount }}</span>
      </div>

      <div class="row">
        <span class="label">会员等级：</span>
        <span class="value level">{{ memberInfo.memberLevel }}</span>
      </div>

      <div class="row">
        <span class="label">会员积分：</span>
        <span class="value points">{{ memberInfo.membershipPoints }}</span>
      </div>

      <div class="row">
        <span class="label">创建时间：</span>
        <span class="value">{{ memberInfo.createTime }}</span>
      </div>

      <div class="action-buttons">
        <button @click="showPrivilege = true">会员特权</button>
        <button @click="showLevelRule = true">等级规则</button>
      </div>
    </div>

    <!-- 会员特权弹窗 -->
    <div class="modal" v-if="showPrivilege">
      <div class="modal-content">
        <h3>🎁 会员特权</h3>
        <ul>
          <li>✨ 会员积分可用于抵扣电影票金额</li>
          <li>🎬 每消费 1 元 = 获得 1 积分</li>
          <li>🍿 积分满 1000 可免费兑换电影小食 1 份</li>
          <li>💳 积分满 3000 可免费兑换 2D 电影票 1 张</li>
        </ul>
        <button class="close-btn" @click="showPrivilege = false">关闭</button>
      </div>
    </div>

    <!-- 等级规则弹窗 -->
    <div class="modal" v-if="showLevelRule">
      <div class="modal-content">
        <h3>⭐ 会员等级规则</h3>
        <ul>
          <li>青铜：0 - 499 积分</li>
          <li>白银：500 - 1499 积分</li>
          <li>黄金：1500 - 2999 积分</li>
          <li>铂金：3000+ 积分</li>
        </ul>
        <button class="close-btn" @click="showLevelRule = false">关闭</button>
      </div>
    </div>

  </div>
</template>

<style scoped>
.member-container {
  max-width: 900px;        /* 宽度加大 */
  margin: 60px auto;       /* 顶部间距更自然 */
  padding: 0 20px;
  font-family: "Microsoft Yahei", sans-serif;
}

/* 页面标题 */
.title {
  text-align: center;
  margin-bottom: 30px;
  color: #A2131D;
  font-size: 26px;
  font-weight: bold;
}

/* 会员卡片容器 */
.card {
  background: #fff;
  border-radius: 12px;
  padding: 40px 60px;
  border: 1px solid #e6e6e6;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.06);
  transition: transform .25s ease;
}

.card:hover {
  transform: translateY(-3px);   /* 鼠标悬浮微动效 */
}

/* 信息行 */
.row {
  margin-bottom: 18px;
  font-size: 18px;
  display: flex;
  gap: 10px;
}

.label {
  width: 110px;
  color: #666;
  text-align: right;
}

.value {
  color: #333;
  font-weight: 500;
}

.level {
  color: #d9a300;
  font-weight: 600;
}

.points {
  color: #C12222;
  font-size: 22px;
  font-weight: 700;
}

/* 两个按钮容器 */
.action-buttons {
  margin-top: 35px;
  display: flex;
  justify-content: center;
  gap: 30px;
}

.action-buttons button {
  padding: 12px 36px;
  border-radius: 6px;
  border: none;
  font-size: 16px;
  cursor: pointer;
  transition: all .3s;
  background: #A2131D;
  color: white;
  letter-spacing: 1px;
}

.action-buttons button:hover {
  background: #870f17;
  transform: translateY(-2px);
}


/* ===== 弹窗样式 ===== */
.modal {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,.5);
  display: flex;
  justify-content: center;
  align-items: center;
  animation: fadeIn .3s ease;
}

.modal-content {
  background: white;
  padding: 28px 36px;
  border-radius: 12px;
  width: 420px;
  box-shadow: 0 10px 30px rgba(0,0,0,.2);
  animation: scaleIn .3s ease;
}

.modal-content h3 {
  text-align: center;
  font-size: 20px;
  margin-bottom: 18px;
  color: #A2131D;
}

.modal-content ul {
  margin: 0;
  padding-left: 18px;
  font-size: 15px;
  color: #333;
  line-height: 1.8;
}

.close-btn {
  margin-top: 20px;
  width: 100%;
  background: #A2131D;
  color: white;
  border: none;
  padding: 10px;
  font-size: 15px;
  cursor: pointer;
  border-radius: 8px;
}

.close-btn:hover {
  background: #870f17;
}

/* 动画 */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes scaleIn {
  from { transform: scale(.85); }
  to { transform: scale(1); }
}
</style>

